import 'package:flutter/material.dart';

import '../base_stateless_widget.dart';
import '../platform/platform.dart';

@deprecated
class BaseGeneralDialog extends BaseStatelessWidget {
  const BaseGeneralDialog({
    Key? baseKey,
    this.barrierDismissible = true,
    this.barrierLabel,
    this.barrierColor = Colors.black54,
    this.transitionDuration = const Duration(milliseconds: 150),
    this.pageBuilder,
    this.child,
    this.transitionBuilder,
    this.useSafeArea = false,
    this.useRootNavigator = true,
    Map<String, dynamic>? cupertino,
    Map<String, dynamic>? material,
  }) : super(
      key: baseKey,
      cupertino: cupertino ?? const <String, dynamic>{},
      material: material ?? const <String, dynamic>{}
  );

  final bool barrierDismissible;
  final String? barrierLabel;
  final Color barrierColor;
  final Duration transitionDuration;
  final RoutePageBuilder? pageBuilder;
  final Widget? child;
  final RouteTransitionsBuilder? transitionBuilder;
  final bool useSafeArea;
  final bool useRootNavigator;

  @override
  Widget buildByCupertino(BuildContext context) {
    return valueFromCupertino('child', child) ?? const SizedBox();
  }

  @override
  Widget buildByMaterial(BuildContext context) {
    return valueFromMaterial('child', child) ?? const SizedBox();
  }

  Future<T?> show<T>(BuildContext context) {
    final bool _barrierDismissible = useCupertino
        ? valueFromCupertino('barrierDismissible', barrierDismissible)
        : valueFromMaterial('barrierDismissible', barrierDismissible);
    final String? _barrierLabel = useCupertino
        ? valueFromCupertino('barrierLabel', barrierLabel)
        : valueFromMaterial('barrierLabel', barrierLabel);
    final Color _barrierColor = useCupertino
        ? valueFromCupertino('barrierColor', barrierColor)
        : valueFromMaterial('barrierColor', barrierColor);
    final Duration _transitionDuration = useCupertino
        ? valueFromCupertino('transitionDuration', transitionDuration)
        : valueFromMaterial('transitionDuration', transitionDuration);
    final RoutePageBuilder? _pageBuilder = useCupertino
        ? valueFromCupertino('pageBuilder', pageBuilder)
        : valueFromMaterial('pageBuilder', pageBuilder);
    final RouteTransitionsBuilder? _transitionBuilder = useCupertino
        ? valueFromCupertino('transitionBuilder', transitionBuilder)
        : valueFromMaterial('transitionBuilder', transitionBuilder);

    return showGeneralDialog<T>(
      context: context,
      barrierDismissible: _barrierDismissible,
      barrierLabel: _barrierLabel,
      barrierColor: _barrierColor,
      transitionDuration: _transitionDuration,
      pageBuilder: _pageBuilder ?? _defaultPageBuilder,
      transitionBuilder: _transitionBuilder ?? _defaultTransitions,
      useRootNavigator: useRootNavigator,
    );
  }

  Widget _defaultPageBuilder(
      BuildContext context,
      Animation<double> animation,
      Animation<double> secondaryAnimation,
      ) {
    final ThemeData theme = Theme.of(context);
    final Widget _pageChild = build(context);
    Widget child;
    if (useSafeArea) {
      child = SafeArea(
        child: Theme(
          data: theme,
          child: _pageChild,
        ),
      );
    } else {
      child = Theme(
        data: theme,
        child: _pageChild,
      );
    }
    return child;
  }

  Widget _defaultTransitions(
      BuildContext context,
      Animation<double> animation,
      Animation<double> secondaryAnimation,
      Widget child,
      ) {
    return FadeTransition(
      opacity: CurvedAnimation(
        parent: animation,
        curve: Curves.easeOut,
      ),
      child: child,
    );
  }
}

// Future<T> showBaseGeneralDialog<T>(
//   BaseGeneralDialog baseGeneralDialog,
//   BuildContext context,
// ) {
//   return baseGeneralDialog.show(context);
// }